home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-15 | 4.9 KB | 122 lines | [TEXT/gamI] |
- ;;;This file contains some sample applications of functions provided
- ;;;in Utilities.scm, since the documentation is pretty slim.
- ;;;
- ;;;You must first load Utilities.scm!!!!
- ;;;
-
-
- ;;;Please look at the menus, and someone will be by to take your order...
- ;;;Here is some sample code to demonstrate how menu stuff is set up
- ;;;This adds a menu pick on the Special menu of MacGambit, "Switch to
- ;;;other menu" which brings up the menu built up in the function
- ;;;nuke-menus. Picking "Quit" on the file menu when this set of menus
- ;;;is up will call restore-menus and return you to the familiar menus
- ;;;One word of caution - menu ids are not recycled, and since we're starting
- ;;;at 145 and can only go up to 255, you can only play this game a limited
- ;;;number of times before you get an error and can't switch to the new menus
- ;;;anymore. It is always possible to switch to the old menus, just type
- ;;;(restore-menus 42)
-
- (define $menufuns #t)
-
- (define (restore-menus dummy)
- (mac#clearmenubar)
- (add-old-menu "Apple" 128) ;item 0
- (add-old-menu "File" 129) ;item 1
- (add-old-menu "Edit" 130) ;item 2
- (add-old-menu "Search" 131) ;item 3
- (add-old-menu "Command" 132) ;item 4
- (add-old-menu "Windows" 133) ;item 5
- ; (add-old-menu "Special" 134) ;item 6
- (set! current-ids #f)
- (mac#insertmenu (mac#getmenu 134) 0)
- (set! current-ids
- (append
- current-ids
- (list (list (mac#getmenu 134)
- "Special"
- (list (list #f "Load..." do-load-file)
- (list #f "Compile..." do-compile-file)
- (list #f "Switch to other menu" $menufuns))))))
- (set! current-subids #f)
- ; (mac#setcursor 1)
- (mac#drawmenubar))
-
- (mac#appendmenu (mac#getmenu 134) "Switch to other menu")
-
- (set! mac#menuselection do-men-selection)
-
- (define (burp item)
- (format #t "File Menu pick item #~s~%" item))
-
- (define (hiccup item)
- (format #t "Edit Menu pick item #~s~%" item))
-
- (define (submenpic item)
- (format #t "Submenu pick item #~s~%" item))
-
- (define (nada item) #t)
-
- (define (nuke-menus dummy)
- (let ((menid 0) (submenid 0))
- (mac#clearmenubar)
- (set! current-ids #f)
- (add-old-menu "Apple" 128) ;item 0
- ; (add-old-menu "File" 129) ;item 1
- (set! menid (add-new-menu "File"))
- ; (format #t "Menu id = ~s~%" menid)
- (add-menu-item menid "New" burp "N" #f #f)
- (disable-menitem menid 1)
- (add-menu-item menid "Open" burp "O" #f #f)
- ; (disable-menitem menid 2)
- (add-menu-item menid "Import" burp "I" #f #f)
- (add-menu-item menid "Close" burp "W" #f #f)
- (add-menu-item menid "Save" burp "S" #f #t)
- (add-menu-item menid "Save As..." burp #f #f #f)
- (add-menu-item menid "Quit" restore-menus "Q" #f #t)
- (set! menid (add-new-menu "Edit")) ;item 2
- ; (format #t "Menu id = ~s~%" menid)
- (add-menu-item menid "Cut" hiccup "X" #f #f)
- (add-menu-item menid "Copy" hiccup "C" #f #f)
- (add-menu-item menid "Paste" hiccup "V" #f #f)
- (add-menu-item menid "Delete" hiccup "D" #f #f)
- (add-menu-item menid "Select All" nada "A" #f #f)
- (add-menu-item menid "Clear" hiccup #f #f #f)
- (add-menu-item menid "Undo" (lambda (foo) (format #t "UNDOOOO~%")) "Z" #f #f)
- (set! menid (add-new-menu "Submenus")) ;item 3
- (set! submenid (add-menu-item menid "First Pick" nada #f #t #f))
- (add-submenu-item menid submenid "Sub1" submenpic)
- (add-submenu-item menid submenid "Sub2" submenpic)))
-
- (set! $menufuns nuke-menus)
- (restore-menus 3)
-
-
- ;;;And now for a completely different format...
- ;;;There is hidden in the bowels of MacGambit a ##format but
- ;;;it always writes to a port and won't write formatted numbers,
- ;;;so here is (format port format-string [restargs]).
- ;;;port is either an output-port (returned from open-output-file)
- ;;;or #t, whence it prints to your MacGambit Interaction window.
- ;;;The format string looks suspiciously like the format string used
- ;;;in Common Lisp, only with a serious lobotomy, or two
- ;;;the special characters are:
- ;;; ~a - display an object (no quotes around strings, etc.)
- ;;; ~s - write an object (strings have quotes)
- ;;; ~d - write a decimal number
- ;;; ~% - force a new line
- ;;; ~i - where i is 1 to 9 - write a fixed-length number where
- ;;; i is the number of places to write, left justified
- ;;; (i.e., decimals are truncated)
- ;;;[restargs] is of course the arguments to be printed according
- ;;;to the format string.
- ;;;
- ;;;error handling is minimal, due to the double lobotomy - one
- ;;;perennial favorite error is not supplying a port (I know it's
- ;;;my favorite). Another error which is not handled helpfully is
- ;;;that of not having the number of restargs match the number of
- ;;;expected arguments in the format string.
-
- (format #t "Now is the time...~%")
- (format #t "you have now been running ~a seconds~%" (truncate (/ (mac#tickcount) 60)))
- (format #t "That's ~5 hours~%" (exact->inexact (/ (mac#tickcount) 60 3600)))